package com.itheima.day12.jiexixml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) throws Exception {
        List<User> list = new ArrayList<>();
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("D:\\javajc_ws\\javaEE\\src\\com\\itheima\\day12\\jiexixml\\users.xml");
        Element rootElement = read.getRootElement();
        List<Element> userList = rootElement.elements("user");
        for (Element user : userList) {
            int age = Integer.parseInt(user.elementText("age"));
            String sex = user.elementText("sex");
            String address = user.elementText("address");

            Element nameele = user.element("name");
            String name = nameele.getText();
            int id = Integer.parseInt(nameele.attributeValue("id"));
            int num = Integer.parseInt(nameele.attributeValue("num"));
            User u = new User(id,num,name,age,sex,address);
            list.add(u);
        }
        list.forEach(System.out::println);


    }
}
